from UIAutoTest.unittest_crud.Login.Get_Login import Get_Login
import time


# 元素定位层
class FindElement(Get_Login):
    def __init__(self):
        # 调用初始化方法，来到登录界面并登录
        Get_Login.__init__(self)
        # 定位文章管理
        self.driver.find_element_by_xpath("//*[@id=\"admin-offcanvas\"]/div/ul/li[10]/a/span[2]").click()
        time.sleep(1)
        self.driver.find_element_by_xpath("//*[@id=\"power-menu-204\"]/li[1]/a/span").click()
        time.sleep(1)
        # 定位文章主页面
        self.driver.get('http://shop-xo.hctestedu.com/admin.php?s=/article/index.html')

    # 定位元素
    def find_element_a(self):
        # 定位文章添加按钮
        return self.driver.find_element_by_xpath('/html/body/div[2]/div[2]/form/div[2]/a[1]')

    def find_element_title(self):
        return self.driver.find_element_by_name('title')

    def find_element_jump_url(self):
        return self.driver.find_element_by_name('jump_url')

    def find_element_div4(self):
        return self.driver.find_element_by_xpath(
            '//div[@class="content"]/form/div[4]//div[@class="am-switch-container"]')

    def find_element_div5(self):
        return self.driver.find_element_by_xpath(
            '//div[@class="content"]/form/div[5]//div[@class="am-switch-container"]')

    def find_element_content(self):
        # iframe表单切换
        iframe_element = self.driver.find_element_by_xpath('//div[@id="edui1_iframeholder"]/iframe')
        self.driver.switch_to_frame(iframe_element)
        return self.driver.find_element_by_xpath('//body[@class="view"]/p')
